package com.example.recyclerviewdemo.utils

import android.content.Context
import android.graphics.Rect
import android.view.View
import androidx.recyclerview.widget.RecyclerView
import com.blankj.utilcode.util.SizeUtils


class MarginItemDecoration: RecyclerView.ItemDecoration {

    private var top = 0
    private var bottom = 0
    private var left = 0
    private var right = 0

    constructor(context: Context)
    constructor(context: Context, margin:Float):this(context){
        val mar = SizeUtils.dp2px(margin)
        this.top =  mar
        this.bottom =  mar
        this.left =  mar
        this.right =  mar
    }

    @JvmOverloads
    constructor(context: Context, topMar:Float, bottomMar:Float, leftMar: Float = 0f, rightMar: Float = 0f):this(context){
        this.top =  SizeUtils.dp2px(topMar)
        this.bottom =  SizeUtils.dp2px(bottomMar)
        this.left =  SizeUtils.dp2px(leftMar)
        this.right =  SizeUtils.dp2px(rightMar)
    }


    override fun getItemOffsets(
        outRect: Rect,
        view: View,
        parent: RecyclerView,
        state: RecyclerView.State
    ) {
        super.getItemOffsets(outRect, view, parent, state)
        outRect.top = top
        outRect.left = left
        outRect.right = right
        outRect.bottom = bottom
    }
}